<!DOCTYPE html>
<html lang=zh>
<head>
    <meta charset="utf-8">
    
    <title>Solr 01：用Intellij IDEA搭建服务 | Tyrival</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="solr可以使用自带的jetty启动，但为了后续开发和调试的方便，还是采用IDEA+tomcat的方式搭建环境。文中主要讲述怎样用Intellij IDEA搭建搜索引擎服务。">
<meta name="keywords" content="server,linux,database">
<meta property="og:type" content="article">
<meta property="og:title" content="Solr 01：用Intellij IDEA搭建服务">
<meta property="og:url" content="http://tyrival.github.io/posts/solr-01/index.html">
<meta property="og:site_name" content="Tyrival">
<meta property="og:description" content="solr可以使用自带的jetty启动，但为了后续开发和调试的方便，还是采用IDEA+tomcat的方式搭建环境。文中主要讲述怎样用Intellij IDEA搭建搜索引擎服务。">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2017-08-21T06:17:53.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Solr 01：用Intellij IDEA搭建服务">
<meta name="twitter:description" content="solr可以使用自带的jetty启动，但为了后续开发和调试的方便，还是采用IDEA+tomcat的方式搭建环境。文中主要讲述怎样用Intellij IDEA搭建搜索引擎服务。">
    

    

    
        <link rel="icon" href="/css/images/logo.png" />
    

    <link rel="stylesheet" href="/libs/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/libs/open-sans/styles.css">
    <link rel="stylesheet" href="/libs/source-code-pro/styles.css">

    <link rel="stylesheet" href="/css/style.css">

    <script src="/libs/jquery/2.1.3/jquery.min.js"></script>
    
    
        <link rel="stylesheet" href="/libs/lightgallery/css/lightgallery.min.css">
    
    
        <link rel="stylesheet" href="/libs/justified-gallery/justifiedGallery.min.css">
    
    
    
    


</head>

<body>
    <div id="container">
        <header id="header">
    <div id="header-main" class="header-inner">
        <div class="outer">
            <a href="/" id="logo">
                <i class="logo"></i>
                <span class="site-title">Tyrival</span>
            </a>
            <nav id="main-nav">
                
                    <a class="main-nav-link" href="http://www.tyrival.com">主页</a>
                
                    <a class="main-nav-link" href="/categories">分类</a>
                
                    <a class="main-nav-link" href="/tags">标签</a>
                
            </nav>
            
                
                <nav id="sub-nav">
                    <div class="profile" id="profile-nav">
                        <a id="profile-anchor" href="javascript:;">
                            <img class="avatar" src="/css/images/avatar.png" />
                            <i class="fa fa-caret-down"></i>
                        </a>
                    </div>
                </nav>
            
            <div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
        <button type="submit" class="search-form-submit"></button>
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="想要查找什么..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>

</div>
        </div>
    </div>
    <div id="main-nav-mobile" class="header-sub header-inner">
        <table class="menu outer">
            <tr>
                
                    <td><a class="main-nav-link" href="http://www.tyrival.com">主页</a></td>
                
                    <td><a class="main-nav-link" href="/categories">分类</a></td>
                
                    <td><a class="main-nav-link" href="/tags">标签</a></td>
                
                <td>
                    
    <div class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
    </div>

                </td>
            </tr>
        </table>
    </div>
</header>

        <div class="outer">
            
                

<aside id="profile">
    <div class="inner profile-inner">
        <div class="base-info profile-block">
            <img id="avatar" src="/css/images/avatar.png" />
            <h2 id="name">周晨煜</h2>
            <h3 id="title">程序员 &amp; 自学狂</h3>
            <span id="location"><i class="fa fa-map-marker"></i>无锡, 中国</span>
            <a id="follow" target="_blank" href="https://github.com/tyrival">关注我</a>
        </div>
        <div class="article-info profile-block">
            <div class="article-info-block">
                45
                <span>文章</span>
            </div>
            <div class="article-info-block">
                19
                <span>标签</span>
            </div>
        </div>
        
        <div class="profile-block social-links">
            <table>
                <tr>
                    
                    
                    <td>
                        <a href="https://github.com/tyrival" target="_blank" title="github" class=tooltip>
                            <i class="fa fa-github"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="https://twitter.com/Tyrival" target="_blank" title="twitter" class=tooltip>
                            <i class="fa fa-twitter"></i>
                        </a>
                    </td>
                    
                </tr>
            </table>
        </div>
        
    </div>
</aside>

            
            <section id="main"><article id="post-solr-01" class="article article-type-post" itemscope itemprop="blogPost">
    <div class="article-inner">
        
        
            <header class="article-header">
                
    
        <h1 class="article-title" itemprop="name">
            Solr 01：用Intellij IDEA搭建服务
        </h1>
    

                
                    <div class="article-meta">
                        
    <div class="article-date">
        <i class="fa fa-calendar"></i>
        <a href="/posts/solr-01/">
            <time datetime="2017-05-27T05:53:05.000Z" itemprop="datePublished">2017-05-27</time>
        </a>
    </div>


                        
    <div class="article-category">
    	<i class="fa fa-folder"></i>
        <a class="article-category-link" href="/categories/系统/">系统</a>
    </div>

                        
    <div class="article-tag">
        <i class="fa fa-tag"></i>
        <a class="tag-link" href="/tags/database/">database</a>, <a class="tag-link" href="/tags/linux/">linux</a>, <a class="tag-link" href="/tags/server/">server</a>
    </div>

                    </div>
                
            </header>
        
        
        <div class="article-entry" itemprop="articleBody">
        
            
            <p>solr可以使用自带的jetty启动，但为了后续开发和调试的方便，还是采用IDEA+tomcat的方式搭建环境。文中主要讲述怎样用Intellij IDEA搭建搜索引擎服务。</p>
<a id="more"></a>
<h3 id="软件准备"><a href="#软件准备" class="headerlink" title="软件准备"></a>软件准备</h3><ul>
<li>Intellij IDEA 2017.1.3</li>
<li>tomcat-8.0.22</li>
<li>solr-6.5.1</li>
<li>mysql-connector-java-5.1.42-bin.jar - mysql驱动</li>
<li>ikanalyzer-solr - 分词匹配，适用于solr-6.5</li>
<li>pinyin4j-2.5.0.jar - 拼音检索</li>
<li>pinyinAnalyzer4.3.1.jar - 拼音检索</li>
</ul>
<h3 id="创建工程"><a href="#创建工程" class="headerlink" title="创建工程"></a>创建工程</h3><p>新建一个文件夹 solr，路径为 /Users/tyrival/Documents/Workspace/solr，进行如下操作：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">* solr-6.5.1\server\solr-webapp\webapp 下所有内容复制到 solr 中</span><br><span class="line">* solr-6.5.1\server\lib 中所有jar复制到 solr\WEB-INF\lib 中</span><br><span class="line">* solr-6.5.1\server\lib\ext 中所有jar复制到 solr\WEB-INF\lib 中</span><br><span class="line">* 新建 solr\src\main\java 文件夹</span><br><span class="line">* solr-6.5.1\server\resources\log4j.properties 复制到 solr\src\main\java 中</span><br><span class="line">* 新建 solr\solrhome 文件夹</span><br><span class="line">* solr-6.5.1\server\solr 中所有文件复制到 solr\solrhome 中</span><br></pre></td></tr></table></figure>
<h3 id="Solrhome"><a href="#Solrhome" class="headerlink" title="Solrhome"></a>Solrhome</h3><p>修改 solr\WEB-INF\web.xml 中的 env-entry-value 值，修改为项目中solrhome的绝对路径</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;env-entry&gt;</span><br><span class="line">	&lt;env-entry-name&gt;solr/home&lt;/env-entry-name&gt;</span><br><span class="line">	&lt;env-entry-value&gt;/Users/tyrival/Documents/Workspace/solr/solrhome&lt;/env-entry-value&gt;</span><br><span class="line">	&lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;</span><br><span class="line">&lt;/env-entry&gt;</span><br></pre></td></tr></table></figure>
<h3 id="配置IDEA"><a href="#配置IDEA" class="headerlink" title="配置IDEA"></a>配置IDEA</h3><p>打开Project Structure（Command + ;）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">Project</span><br><span class="line">* SDK -&gt; java 1.8</span><br><span class="line"></span><br><span class="line">Modules</span><br><span class="line">* 选中目录树上的solr</span><br><span class="line">* Sources标签，设置src\main\java为Sources类型</span><br><span class="line">* Paths标签，设置Output path：/Users/tyrival/Documents/Workspace/solr/WEB-INF/classes，勾选Exclude output paths</span><br><span class="line">* 选中目录树上的Web，如果没有，可以点上面的加号新建一个Web，然后点右下角出现的Fix按钮</span><br><span class="line">* 勾选右下方的Source Roots</span><br><span class="line"></span><br><span class="line">Libraries</span><br><span class="line">* 点顶部的+号，选择 solr\WEB-INF\lib 文件夹</span><br><span class="line"></span><br><span class="line">Artifacts</span><br><span class="line">* 点+号，选择Web Application:Exploded =&gt; From Modules</span><br><span class="line"></span><br><span class="line">OK</span><br></pre></td></tr></table></figure>
<p>打开Run/Debug Configurations，配置tomcat</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">* 点左上角+号，选择Tomcat Server =&gt; Local</span><br><span class="line">* 输入Name</span><br><span class="line"></span><br><span class="line">Server</span><br><span class="line">* Open browser中，勾选After launch，输入默认打开路径为 http://localhost:8080/solr/index.html</span><br><span class="line"></span><br><span class="line">Deployment</span><br><span class="line">* 点面板中部的+号，选择Artifact =&gt; 第3步创建的solr:Web exploded</span><br><span class="line">* Application context改为 /solr</span><br><span class="line"></span><br><span class="line">OK</span><br></pre></td></tr></table></figure>
<h3 id="启动"><a href="#启动" class="headerlink" title="启动"></a>启动</h3><p>点运行，浏览器打开<a href="http://localhost:8080/solr/index.html，服务搭建成功。" target="_blank" rel="noopener">http://localhost:8080/solr/index.html，服务搭建成功。</a></p>
<h3 id="配置core"><a href="#配置core" class="headerlink" title="配置core"></a>配置core</h3><ul>
<li>新建 solr\solrhome\my_solr 文件夹</li>
<li>solr-6.5.1\example\example-DIH\solr\solr 中所有文件复制到刚创建的 my_solr 中</li>
<li>将mysql驱动 mysql-connector-java-5.1.42-bin.jar 复制到 solr/WEB-INF/lib 中，</li>
<li>修改 my_solr\conf\solr-data-config.xml</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;dataConfig&gt;</span><br><span class="line">   &lt;!-- 数据库连接 --&gt;</span><br><span class="line">   &lt;dataSource type=&quot;JdbcDataSource&quot;</span><br><span class="line">               driver=&quot;com.mysql.jdbc.Driver&quot;</span><br><span class="line">               url=&quot;jdbc:mysql://10.211.55.82:3306/test&quot;</span><br><span class="line">               user=&quot;root&quot;</span><br><span class="line">               password=&quot;root&quot;/&gt;</span><br><span class="line"></span><br><span class="line">   &lt;!-- 数据表映射 --&gt;</span><br><span class="line">   &lt;document name=&quot;solr_mysql_test&quot;&gt;</span><br><span class="line">       &lt;entity name=&quot;solrTest&quot;</span><br><span class="line">               pk=&quot;id&quot;</span><br><span class="line">               query=&quot;select * from solrTest&quot;</span><br><span class="line">               deltaImportQuery=&quot;select * from solrTest where id = &apos;$&#123;dih.delta.id&#125;&apos;&quot;</span><br><span class="line">               deltaQuery=&quot;select id from solrTest where updateTime &gt; &apos;$&#123;dataimporter.last_index_time&#125;&apos;&quot;/&gt;</span><br><span class="line"></span><br><span class="line">       &lt;field column=&quot;id&quot; name=&quot;id&quot;/&gt;</span><br><span class="line">       &lt;field column=&quot;context&quot; name=&quot;context&quot;/&gt;</span><br><span class="line">       &lt;field column=&quot;updateTime&quot; name=&quot;updateTime&quot;/&gt;</span><br><span class="line">       &lt;field column=&quot;sort&quot; name=&quot;sort&quot;/&gt;</span><br><span class="line">   &lt;/document&gt;</span><br><span class="line">&lt;/dataConfig&gt;</span><br></pre></td></tr></table></figure>
<ul>
<li>修改 my_solr\conf\managed-schema，在schema标签下添加</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- 这里没有添加field = id，因为managed-schema中默认已经存在了 --&gt;</span><br><span class="line">&lt;field name=&quot;context&quot; type=&quot;string&quot; indexed=&quot;true&quot; stored=&quot;true&quot; multiValued=&quot;false&quot;/&gt;  </span><br><span class="line">&lt;field name=&quot;updateTime&quot; type=&quot;date&quot; indexed=&quot;true&quot; stored=&quot;true&quot; multiValued=&quot;false&quot;/&gt;  </span><br><span class="line">&lt;field name=&quot;sort&quot; type=&quot;int&quot; indexed=&quot;true&quot; stored=&quot;true&quot; multiValued=&quot;false&quot;/&gt;</span><br></pre></td></tr></table></figure>
<p>   这里可以将managed-schema复制为schema.xml，然后修改内容，这样对IDEA来说更清晰。</p>
<h3 id="MySql"><a href="#MySql" class="headerlink" title="MySql"></a>MySql</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">CREATE TABLE `solrTest` (  </span><br><span class="line"> `id` int(11) NOT NULL AUTO_INCREMENT COMMENT &apos;id&apos;,  </span><br><span class="line"> `context` varchar(255) DEFAULT NULL COMMENT &apos;context&apos;,  </span><br><span class="line"> `updateTime` datetime DEFAULT NULL COMMENT &apos;updateTime&apos;,  </span><br><span class="line"> `sort` int(11) DEFAULT &apos;1&apos; COMMENT &apos;排序&apos;,  </span><br><span class="line"> PRIMARY KEY (`id`)  </span><br><span class="line">) DEFAULT CHARSET=utf8;</span><br></pre></td></tr></table></figure>
<p>   插入几条测试数据。</p>
<h3 id="导入插件"><a href="#导入插件" class="headerlink" title="导入插件"></a>导入插件</h3><ul>
<li>solr-6.5.1\dist 下的 solr-dataimporthandler-6.0.0.jar 和 solr-dataimporthandler-extras-6.0.0.jar 复制到 solr\WEB-INF\lib 中</li>
</ul>
<h3 id="数据导入"><a href="#数据导入" class="headerlink" title="数据导入"></a>数据导入</h3><ul>
<li><p>打开<a href="http://localhost:8080/solr/index.html，左侧Core" target="_blank" rel="noopener">http://localhost:8080/solr/index.html，左侧Core</a> Selector选择my_solr</p>
</li>
<li><p>选择Dataimport，点击右侧Execute，刷新后出现如下信息</p>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Indexing completed. Added/Updated: 3 documents. Deleted 0 documents. (Duration: 01s)</span><br><span class="line">Requests: 1 1/s, Fetched: 3 3/s, Skipped: 0 , Processed: 3 3/s</span><br><span class="line">Started: about 8 hours ago</span><br></pre></td></tr></table></figure>
<ul>
<li>展开Raw Status-Output</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	&quot;responseHeader&quot;: &#123;</span><br><span class="line">		&quot;status&quot;: 0,</span><br><span class="line">		&quot;QTime&quot;: 0</span><br><span class="line">	&#125;,</span><br><span class="line">	&quot;initArgs&quot;: [</span><br><span class="line">		&quot;defaults&quot;,</span><br><span class="line">		[</span><br><span class="line">			&quot;config&quot;,</span><br><span class="line">			&quot;solr-data-config.xml&quot;</span><br><span class="line">		]</span><br><span class="line">	],</span><br><span class="line">	&quot;command&quot;: &quot;status&quot;,</span><br><span class="line">	&quot;status&quot;: &quot;idle&quot;,</span><br><span class="line">	&quot;importResponse&quot;: &quot;&quot;,</span><br><span class="line">	&quot;statusMessages&quot;: &#123;</span><br><span class="line">	&quot;Total Requests made to DataSource&quot;: &quot;1&quot;,</span><br><span class="line">	&quot;Total Rows Fetched&quot;: &quot;3&quot;,</span><br><span class="line">	&quot;Total Documents Processed&quot;: &quot;3&quot;,</span><br><span class="line">	&quot;Total Documents Skipped&quot;: &quot;0&quot;,</span><br><span class="line">	&quot;Full Dump Started&quot;: &quot;2017-05-27 14:47:32&quot;,</span><br><span class="line">	&quot;&quot;: &quot;Indexing completed. Added/Updated: 3 documents. Deleted 0 documents.&quot;,</span><br><span class="line">	&quot;Committed&quot;: &quot;2017-05-27 14:47:33&quot;,</span><br><span class="line">	&quot;Time taken&quot;: &quot;0:0:0.602&quot;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li><p>如果导入失败，可以打开Logging查看错误日志</p>
</li>
<li><p>打开Query，点击Execute Query可以查看到导入的数据</p>
</li>
</ul>
<h3 id="分词、停止词、扩展词"><a href="#分词、停止词、扩展词" class="headerlink" title="分词、停止词、扩展词"></a>分词、停止词、扩展词</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">* 复制 IKAnalyze-solr 中的 ik-analyzer-solr5-5.x.jar 和 solr-analyzer-ik-5.1.0.jar 到 solr\WEB-INF\lib 中</span><br><span class="line">* 复制 IKAnalyze-solr 中的 ext.dic、stopword.dic、IKAnalyzer.cfg.xml 到 solr\src\main\java  中</span><br><span class="line">* 修改 IKAnalyzer.cfg.xml</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;!DOCTYPE properties SYSTEM &quot;http://java.sun.com/dtd/properties.dtd&quot;&gt;</span><br><span class="line">&lt;properties&gt;</span><br><span class="line">	&lt;comment&gt;IK Analyzer 扩展配置&lt;/comment&gt;</span><br><span class="line">	&lt;!--用户可以在这里配置自己的扩展字典 --&gt;</span><br><span class="line">	&lt;entry key=&quot;ext_dict&quot;&gt;ext.dic;&lt;/entry&gt;</span><br><span class="line">	&lt;!--用户可以在这里配置自己的扩展停止词字典--&gt;</span><br><span class="line">	&lt;entry key=&quot;ext_stopwords&quot;&gt;stopword.dic;&lt;/entry&gt;</span><br><span class="line">&lt;/properties&gt;</span><br></pre></td></tr></table></figure>
<ul>
<li>修改 solr\solrhome\my_solr\conf\managed-schema，注册分词插件</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&lt;fieldType name=&quot;text_ik&quot; class=&quot;solr.TextField&quot;&gt;</span><br><span class="line">  &lt;analyzer type=&quot;index&quot;&gt;</span><br><span class="line">  	&lt;tokenizer class=&quot;org.apache.lucene.analysis.ik.IKTokenizerFactory&quot; useSmart=&quot;true&quot;/&gt;</span><br><span class="line">  &lt;/analyzer&gt;</span><br><span class="line">  &lt;analyzer type=&quot;query&quot;&gt;</span><br><span class="line">  	&lt;tokenizer class=&quot;org.apache.lucene.analysis.ik.IKTokenizerFactory&quot; useSmart=&quot;true&quot;/&gt;</span><br><span class="line">  &lt;/analyzer&gt;</span><br><span class="line">&lt;/fieldType&gt;</span><br></pre></td></tr></table></figure>
<ul>
<li>修改 solr\solrhome\my_solr\conf\managed-schema 中的 field=context，启用分词查询</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;field name=&quot;context&quot; type=&quot;text_ik&quot; indexed=&quot;true&quot; stored=&quot;true&quot; multiValued=&quot;false&quot;/&gt;</span><br></pre></td></tr></table></figure>
<ul>
<li>在浏览器左侧进入my_solr =&gt; Query， 修改 q 为 context:关键词，就可以按照关键字进行分词匹配，查出结果。</li>
<li>停止词表示在查询中需要忽略的词，比如语气词“啊”、“呀”或者“的”、“得”等，可在stopword.dic中配置</li>
<li>扩展词表示部分非常用词汇、专业词汇、新造词，例如：“炉石传说”、“吉安娜”等，可在ext.dic重配置</li>
</ul>
<h3 id="拼音检索"><a href="#拼音检索" class="headerlink" title="拼音检索"></a>拼音检索</h3><ul>
<li><p>复制 pinyin4j-2.5.0.jar、pinyinAnalyzer.jar 到 solr/WEB-INF/lib 中</p>
</li>
<li><p>在 solr\solrhome\my_solr\conf\managed-schema 的 schema 标签中增加：</p>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;fieldType name=&quot;text_pinyin&quot; class=&quot;solr.TextField&quot; positionIncrementGap=&quot;0&quot;&gt;</span><br><span class="line">    &lt;analyzer type=&quot;index&quot;&gt;</span><br><span class="line">        &lt;tokenizer class=&quot;org.apache.lucene.analysis.ik.IKTokenizerFactory&quot;/&gt;</span><br><span class="line">        &lt;filter class=&quot;com.shentong.search.analyzers.PinyinTransformTokenFilterFactory&quot; minTermLenght=&quot;2&quot; /&gt;</span><br><span class="line">        &lt;filter class=&quot;com.shentong.search.analyzers.PinyinNGramTokenFilterFactory&quot; minGram=&quot;1&quot; maxGram=&quot;20&quot; /&gt;</span><br><span class="line">    &lt;/analyzer&gt;</span><br><span class="line">    &lt;analyzer type=&quot;query&quot;&gt;</span><br><span class="line">        &lt;tokenizer class=&quot;org.apache.lucene.analysis.ik.IKTokenizerFactory&quot;/&gt;</span><br><span class="line">        &lt;filter class=&quot;com.shentong.search.analyzers.PinyinTransformTokenFilterFactory&quot; minTermLenght=&quot;2&quot; /&gt;</span><br><span class="line">        &lt;filter class=&quot;com.shentong.search.analyzers.PinyinNGramTokenFilterFactory&quot; minGram=&quot;1&quot; maxGram=&quot;20&quot; /&gt;</span><br><span class="line">    &lt;/analyzer&gt;</span><br><span class="line">&lt;/fieldType&gt;</span><br></pre></td></tr></table></figure>
<ul>
<li>在web端，Analysis中校验拼音检索</li>
</ul>
<h3 id="同义词"><a href="#同义词" class="headerlink" title="同义词"></a>同义词</h3><ul>
<li>在 solr\solrhome\my_solr\conf\managed-schema 的 schema 标签中增加：</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&lt;fieldType name=&quot;text_syn&quot; class=&quot;solr.TextField&quot;&gt;</span><br><span class="line">    &lt;analyzer type=&quot;query&quot;&gt;</span><br><span class="line">        &lt;tokenizer class=&quot;solr.WhitespaceTokenizerFactory&quot;/&gt;</span><br><span class="line">        &lt;filter class=&quot;solr.LowerCaseFilterFactory&quot;/&gt;</span><br><span class="line">    &lt;/analyzer&gt;</span><br><span class="line">    &lt;analyzer type=&quot;index&quot;&gt;</span><br><span class="line">        &lt;tokenizer class=&quot;solr.WhitespaceTokenizerFactory&quot;/&gt;</span><br><span class="line">        &lt;filter class=&quot;solr.SynonymFilterFactory&quot; synonyms=&quot;synonyms.txt&quot; ignoreCase=&quot;true&quot; expand=&quot;false&quot;/&gt;</span><br><span class="line">        &lt;filter class=&quot;solr.LowerCaseFilterFactory&quot;/&gt;</span><br><span class="line">    &lt;/analyzer&gt;</span><br><span class="line">&lt;/fieldType&gt;</span><br></pre></td></tr></table></figure>
<ul>
<li>修改 solr\solrhome\my_solr\conf\managed-schema 中的 field=context，启用同义词查询</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;field name=&quot;context&quot; type=&quot;text_syn&quot; indexed=&quot;true&quot; stored=&quot;true&quot; multiValued=&quot;false&quot;/&gt;</span><br></pre></td></tr></table></figure>
<ul>
<li>在 solr\solrhome\my_solr\conf\synonyms.txt 中增加同义词映射：</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 格式1，箭头表示映射</span><br><span class="line">测试 =&gt; test</span><br><span class="line"></span><br><span class="line"># 格式2，用英文逗号隔开同义词组</span><br><span class="line">测试,test,tst</span><br></pre></td></tr></table></figure>
<ul>
<li>在web端，Analysis中校验同义词检索</li>
</ul>

        
        </div>
        <footer class="article-footer">
            <div class="share-container">



</div>

    <a data-url="http://tyrival.github.io/posts/solr-01/" data-id="cjs9z0xpr002y5aa7z8psua7h" class="article-share-link"><i class="fa fa-share"></i>分享到</a>
<script>
    (function ($) {
        // Prevent duplicate binding
        if (typeof(__SHARE_BUTTON_BINDED__) === 'undefined' || !__SHARE_BUTTON_BINDED__) {
            __SHARE_BUTTON_BINDED__ = true;
        } else {
            return;
        }
        $('body').on('click', function() {
            $('.article-share-box.on').removeClass('on');
        }).on('click', '.article-share-link', function(e) {
            e.stopPropagation();

            var $this = $(this),
                url = $this.attr('data-url'),
                encodedUrl = encodeURIComponent(url),
                id = 'article-share-box-' + $this.attr('data-id'),
                offset = $this.offset(),
                box;

            if ($('#' + id).length) {
                box = $('#' + id);

                if (box.hasClass('on')){
                    box.removeClass('on');
                    return;
                }
            } else {
                var html = [
                    '<div id="' + id + '" class="article-share-box">',
                        '<input class="article-share-input" value="' + url + '">',
                        '<div class="article-share-links">',
                            '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>',
                            '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>',
                            '<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>',
                            '<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>',
                        '</div>',
                    '</div>'
                ].join('');

              box = $(html);

              $('body').append(box);
            }

            $('.article-share-box.on').hide();

            box.css({
                top: offset.top + 25,
                left: offset.left
            }).addClass('on');

        }).on('click', '.article-share-box', function (e) {
            e.stopPropagation();
        }).on('click', '.article-share-box-input', function () {
            $(this).select();
        }).on('click', '.article-share-box-link', function (e) {
            e.preventDefault();
            e.stopPropagation();

            window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
        });
    })(jQuery);
</script>

            
    

        </footer>
    </div>
    
        
<nav id="article-nav">
    
        <a href="/posts/pi-01-initial/" id="article-nav-newer" class="article-nav-link-wrap">
            <strong class="article-nav-caption">上一篇</strong>
            <div class="article-nav-title">
                
                    树莓派 01：系统安装和配置
                
            </div>
        </a>
    
    
        <a href="/posts/server-jdk-mysql/" id="article-nav-older" class="article-nav-link-wrap">
            <strong class="article-nav-caption">下一篇</strong>
            <div class="article-nav-title">CentOS 7 安装JDK、MySql</div>
        </a>
    
</nav>


    
</article>


    
    
        <section id="comments">
	<div id="commentContainer"></div>
</section>
    

</section>
            
                
<aside id="sidebar">
   
        
    <div class="widget-wrap">
        <h3 class="widget-title">最新文章</h3>
        <div class="widget">
            <ul id="recent-post" class="no-thumbnail">
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/系统/">系统</a></p>
                            <p class="item-title"><a href="/posts/redis-cluster-by-docker/" class="title">Docker 部署 Redis5.0 集群，以及 ioredis 连接集群</a></p>
                            <p class="item-date"><time datetime="2019-02-18T05:20:49.552Z" itemprop="datePublished">2019-02-18</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/hadoop/">hadoop</a></p>
                            <p class="item-title"><a href="/posts/hadoop-docker-01/" class="title">Docker+Hadoop 01：环境部署</a></p>
                            <p class="item-date"><time datetime="2019-01-02T23:58:03.975Z" itemprop="datePublished">2019-01-03</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/后端/">后端</a></p>
                            <p class="item-title"><a href="/posts/springboot-tesseract/" class="title">SpringBoot05：Spring Boot与Tesseract集成</a></p>
                            <p class="item-date"><time datetime="2018-07-08T06:26:12.000Z" itemprop="datePublished">2018-07-08</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/后端/">后端</a></p>
                            <p class="item-title"><a href="/posts/springboot-elastic/" class="title">SpringBoot04：基于Docker和Spring Boot部署开发Elastic</a></p>
                            <p class="item-date"><time datetime="2018-07-08T06:25:55.000Z" itemprop="datePublished">2018-07-08</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/后端/">后端</a></p>
                            <p class="item-title"><a href="/posts/springboot-solr/" class="title">SpringBoot03：基于Docker和Spring Boot部署开发Solr</a></p>
                            <p class="item-date"><time datetime="2018-07-08T06:25:50.000Z" itemprop="datePublished">2018-07-08</time></p>
                        </div>
                    </li>
                
            </ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">分类</h3>
        <div class="widget">
            <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/hadoop/">hadoop</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/iOS/">iOS</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/前端/">前端</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/后端/">后端</a><span class="category-list-count">8</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/工具/">工具</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/服务器/">服务器</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/硬件/">硬件</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/算法/">算法</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/系统/">系统</a><span class="category-list-count">4</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">标签</h3>
        <div class="widget">
            <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/algorithm/">algorithm</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cloud/">cloud</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/css/">css</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/database/">database</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/">docker</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/f-k-ie/">f**k ie</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hadoop/">hadoop</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/javascript/">javascript</a><span class="tag-list-count">12</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/less/">less</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mac/">mac</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/">python</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/raspberry/">raspberry</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/server/">server</a><span class="tag-list-count">12</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/swift/">swift</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tomcat/">tomcat</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vue/">vue</a><span class="tag-list-count">2</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">标签云</h3>
        <div class="widget tagcloud">
            <a href="/tags/algorithm/" style="font-size: 14px;">algorithm</a> <a href="/tags/cloud/" style="font-size: 10px;">cloud</a> <a href="/tags/css/" style="font-size: 12px;">css</a> <a href="/tags/database/" style="font-size: 14px;">database</a> <a href="/tags/docker/" style="font-size: 10px;">docker</a> <a href="/tags/f-k-ie/" style="font-size: 14px;">f**k ie</a> <a href="/tags/git/" style="font-size: 12px;">git</a> <a href="/tags/hadoop/" style="font-size: 18px;">hadoop</a> <a href="/tags/java/" style="font-size: 16px;">java</a> <a href="/tags/javascript/" style="font-size: 20px;">javascript</a> <a href="/tags/less/" style="font-size: 10px;">less</a> <a href="/tags/linux/" style="font-size: 14px;">linux</a> <a href="/tags/mac/" style="font-size: 10px;">mac</a> <a href="/tags/python/" style="font-size: 10px;">python</a> <a href="/tags/raspberry/" style="font-size: 12px;">raspberry</a> <a href="/tags/server/" style="font-size: 20px;">server</a> <a href="/tags/swift/" style="font-size: 10px;">swift</a> <a href="/tags/tomcat/" style="font-size: 10px;">tomcat</a> <a href="/tags/vue/" style="font-size: 12px;">vue</a>
        </div>
    </div>

    
        
    <div class="widget-wrap widget-list">
        <h3 class="widget-title">链接</h3>
        <div class="widget">
            <ul>
                
            </ul>
        </div>
    </div>


    
    <div id="toTop" class="fa fa-angle-up"></div>
</aside>

            
        </div>
        <footer id="footer">
    <div class="outer">
        <div id="footer-info" class="inner">
            &copy; 2019 Tyrival<br>
            Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>. Theme by <a href="http://github.com/ppoffice">PPOffice</a>
        </div>
    </div>
</footer>
        


    
        <script src="/libs/lightgallery/js/lightgallery.min.js"></script>
        <script src="/libs/lightgallery/js/lg-thumbnail.min.js"></script>
        <script src="/libs/lightgallery/js/lg-pager.min.js"></script>
        <script src="/libs/lightgallery/js/lg-autoplay.min.js"></script>
        <script src="/libs/lightgallery/js/lg-fullscreen.min.js"></script>
        <script src="/libs/lightgallery/js/lg-zoom.min.js"></script>
        <script src="/libs/lightgallery/js/lg-hash.min.js"></script>
        <script src="/libs/lightgallery/js/lg-share.min.js"></script>
        <script src="/libs/lightgallery/js/lg-video.min.js"></script>
    
    
        <script src="/libs/justified-gallery/jquery.justifiedGallery.min.js"></script>
    
    
        <script type="text/x-mathjax-config">
            MathJax.Hub.Config({ tex2jax: { inlineMath: [['$','$'], ['\\(','\\)']] } });
        </script>
        <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>
    



<!-- Custom Scripts -->
<script src="/js/main.js"></script>

    </div>
</body>
</html>